/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class code1 {
    //二叉树的右视图
    List<Integer> ret = new ArrayList<>();
    public List<Integer> rightSideView(TreeNode root) {
        dfs(root,0);
        return ret;
    }

    public void dfs(TreeNode root,int dept) {
        if(root == null) {
            return;
        }

        dept++;//局部

        if(dept > ret.size()) {
            ret.add(root.val);
        }

        dfs(root.right,dept);

        dfs(root.left,dept);


    }
}